package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    //新增
    @PostMapping
    public Result insert(@RequestBody CategoryDTO categoryDTO){
        categoryService.insert(categoryDTO);
        return Result.success();
    }
  //  根据类型查找
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type){
        List<Category> list1 = categoryService.list(type);
        return Result.success(list1);
    }
    //分类分页查询
    @GetMapping("/page")
    public Result page(CategoryPageQueryDTO categoryDTO){
       PageResult pageResult = categoryService.page(categoryDTO);
        return Result.success(pageResult);
    }
    //修改分类
    @PutMapping
    public Result update( @RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }
    //根据ID删除
    @DeleteMapping
    public Result<String> delete( Long id){
        categoryService.delete(id);
        return Result.success();
    }
    //启用禁用
    @PostMapping("status/{status}")
    public Result updateStatus(@PathVariable Integer status ,Long id){
        categoryService.updateStatus(status, id);
        return Result .success();

    }


}
